package lib

import (
	"RMS/app/shop/model"
	"RMS/common"
	"RMS/common/cache"
	"context"
	"github.com/go-redis/redis/v8"
	"strconv"
)

func ImplCartList(ctx context.Context, req *model.CartListReq) *model.CartListResp {
	resp := &model.CartListResp{}
	key := cache.GetCartKey(ctx, strconv.FormatInt(int64(req.Id), 10))
	res, err := cache.RDB.HGetAll(ctx, key).Result()
	if err == redis.Nil || err == nil {
		resp.Status = common.SuccessCode
		resp.Message = common.SuccessMessage
		if res != nil {
			data := make([]map[string]string, 0)
			data = append(data, res)
			resp.Data = data
		}
		return resp
	} else {
		resp.Status = common.ErrCode
		resp.Message = common.FindErrMessage
		return resp
	}
}
